<%@page pageEncoding="utf-8" %>
<script type="text/javascript">
	$(function(){
		$.ajax({
				"type":"GET",
				"datatype":"JSON",
				"url":"${pageContext.request.contextPath}/menu/queryMenu",
				success:function(data){
					
					$.each(data,function(index,menu){
						
						var content="<div align='center'>";
						
						$.each(menu.children,function(i,child){
							
							//js不允许直接传递对象类型的参数，将json对象转换为json格式的字符串传递
							var childs= JSON.stringify(child);
							//console.log(child)
							content+="<br><a id="+child.id+" class='easyui-linkbutton' data-options='plain:true,iconCls:\""+child.iconCls+"\"' onclick='addTab("+childs+")' >"+child.title+"</a><br>";
						});
						content+="</div>";
						
						$('#menu_accordion').accordion('add', {
							title: menu.title,
							iconCls:menu.iconCls,
							content: content,
							selected: false
						});
					});
				}
			});	
	});
				//点击添加选项卡
			var titl;	
	function addTab(child){
			var tit = $("#tt").tabs('exists',child.title);
			titl=child.title;
			if(!tit){
				// add a new tab panel    
				$('#tt').tabs('add',{    
				    title:child.title,    
				    href:child.url,   
				    closable:true,    
				});
			}else{
				$("#tt").tabs('select',child.title);		
			}
	}
</script>
<div id="menu_accordion"  class="easyui-accordion" data-options="fit:true" style="width:180px">
	      
</div>